/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean;

import entities.Address;
import entities.UserProject;
import interfaces.UserProjectInterface;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Thibault Manage registration of a new account.
 */
@ManagedBean(name = "registrationBean")
@ViewScoped
public class RegistrationBean implements Serializable {

    private static final long serialVersionUID = 1L;
    @EJB
    UserProjectInterface userEJB;
    private String mail;
    private String password;
    private String firstName;
    private String lastName;
    private String city;
    private String street;
    private int number;
    private int zipCode;

    public void createAccount() {
        UserProject up = new UserProject(firstName, lastName, mail, password);

        if (city.equals("") || street.equals("") || number == 0 || zipCode == 0) {
            FacesMessage msg = new FacesMessage("Billing informations incomplete, no delivery address created.");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        } else {
            up.getAdresses().add(new Address(street, city, zipCode, number, up));
        }
        userEJB.createUserProject(up);
        FacesMessage msg = new FacesMessage("New account created.");
        FacesContext.getCurrentInstance().addMessage(null, msg);


    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public int getZipCode() {
        return zipCode;
    }

    public void setZipCode(int zipCode) {
        this.zipCode = zipCode;
    }
}
